package com.chilly.other.pattern.strategy2;

import org.springframework.stereotype.Component;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

@Component
public class StrategyFactory implements Factory {
    // 该map用来存放策略名和对应策略类
    private Map<String, Strategy> map = new ConcurrentHashMap<String, Strategy>();

    @Override
    public Strategy createStrategy(String strategyName) {
        return map.get(strategyName);
    }

    // 注册策略类到工厂的map中
    @Override
    public void registerStrategy(Strategy strategy) {
        map.put(strategy.getStrategyName(), strategy);
    }
}
